 /**
   * Copyright 2014 Viettel Telecom. All rights reserved.
   * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
   */
 package com.viettel.core.dao.cms; 
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.viettel.core.entities.cms.QuestionsHistory;
import com.viettel.core.enumtype.QuestionsStatus;
import com.viettel.core.exceptions.DataAccessException;
import com.viettel.core.repo.IRepository;
 /**
   *  Mo ta muc dich cua lop (interface)
   *  @author: TuanTM20
   *  @version:  
   *  @since: 11/07/2014
   */
 public class QuestionsHistoryDAOImpl implements QuestionsHistoryDAO { 
	 private IRepository repo; 
		
	 	public void setRepo(IRepository repo) {
			this.repo = repo;
		}
 
	/**@author TuanTM20
 	 * @since 11/07/2014
  	 */
 	@Override 
	public QuestionsHistory getQuestionsHistoryById(Integer id) throws DataAccessException { 
		return repo.getEntityById(QuestionsHistory.class, id); 
	} 
 
 	/**@author TuanTM20
 	 * @since 11/07/2014
  	 */
 	@Override 
	public QuestionsHistory createQuestionsHistory(QuestionsHistory questionsHistory) 
			throws DataAccessException { 
		if (questionsHistory == null) { 
			throw new IllegalArgumentException("questionsHistory"); 
		} 
		repo.create(questionsHistory); 
		return repo.getEntityById(QuestionsHistory.class, questionsHistory.getId()); 
	} 
 
 	/**@author TuanTM20
 	 * @since 11/07/2014
  	 */
 	@Override 
	public void updateQuestionsHistory(QuestionsHistory questionsHistory) throws DataAccessException { 
		if (questionsHistory == null) { 
			throw new IllegalArgumentException("questionsHistory"); 
		} 
		repo.update(questionsHistory); 
	} 
 
 	/**@author TuanTM20
 	 * @since 11/07/2014
  	 */
 	@Override 
	public void deleteQuestionsHistory(QuestionsHistory questionsHistory) throws DataAccessException { 
		if (questionsHistory == null) { 
			throw new IllegalArgumentException("questionsHistory"); 
		} 
		repo.delete(questionsHistory); 
	}

 	/**@author TuanTM20
 	 * @since 11/07/2014
  	 */
	@Override
	public List<QuestionsHistory> getListQuestionsHistoryBy(Integer questionId, Integer cmsUserId) throws DataAccessException{
		List<Object> params = new ArrayList<Object>();
		String sql = "SELECT * FROM QUESTIONS_HISTORY  where STATUS = 2 ";
		if (questionId != null) {
			sql+= " AND QUESTION_ID = ?";
			params.add(questionId);
		}
		if (cmsUserId != null) {
			sql += " AND CMS_USER_ID = ?";
			params.add(cmsUserId);
		}
		
		
		return repo.getListBySQL(QuestionsHistory.class, sql, params);
	}
} 
 
